#include <iostream>

// 函数重载和运算符重载属于静态多态
// 动态多态：派生类和虚函数

class Animal
{
public:
    virtual void speak()
    {
        std::cout << "animal is speaking" << std::endl;
    }
};

class Cat : public Animal
{
public:
    void speak()
    {
        std::cout << "cat is speaking" << std::endl;
    }
};

class Dog : public Animal
{
public:
    void speak()
    {
        std::cout << "dog is speaking" << std::endl;
    }
};

void doSpeak(Animal& animal)   
{
    animal.speak();
}

void test01()
{
    Cat cat;
    doSpeak(cat);

    Dog dog;
    doSpeak(dog);
}

void test02()
{
    std::cout << sizeof(Animal) << std::endl;
}


int main()
{
    test02();
    return 0;
}

/*
vfptr：虚函数指针 指向vf table
virtual funtion table
表内部：虚函数的地址
&Animal::speak
子类重写了虚函数，那么就会替换掉父类的虚函数地址
*/